let lists={
  name:'simba',
  home:'javascript'
}
const socket=io()
const chatfrom=document.querySelector('.chatfrom')
const chantMessages=document.querySelector('.mains_right')
var mainParm
var time = new Date();
console.log(chatfrom)
// 获取从服务器发送的消息
socket.on('message',(message)=>{
  outputDes(message)
    //滚顶条
    console.log(chantMessages.scrollTop)
    chantMessages.scrollTop=chantMessages.scrollHeight
    console.log(message)
})
// 监听消息提交sumbit
chatfrom.addEventListener('submit',e=>{
    e.preventDefault();

    // 获取提交的消息
const mainMsg=e.target.elements.msg.value
mainParm={
name:lists.name,
home:lists.home,
text:mainMsg,
time:time.toLocaleString( )
}
// 清空input输入框
e.target.elements.msg.value=''
outputDes(mainParm)
socket.emit('chatMessage',mainParm)
})


function outputDes(message){
  $('.mains_right').append(`
   
  <div class="information">
  <div class="top">${message.name}  <p>${message.time}</p></div>
  
  <p class="chat_mass">
    ${message.text}
  </p>
  </div>
  
  `)
}

   